
import java.util.Date;



import org.hibernate.Session;
import org.hibernate.Transaction;

import pl.edu.pk.cc.common.dto.CCAgreementDTO;
import pl.edu.pk.cc.common.dto.CCCallHistoryDTO;
import pl.edu.pk.cc.common.dto.CCClientDTO;
import pl.edu.pk.cc.common.dto.CCEmploymentDTO;
import pl.edu.pk.cc.common.dto.CCLoginDataDTO;
import pl.edu.pk.cc.common.dto.CCProjectsDTO;
import pl.edu.pk.cc.common.dto.CCSaleDTO;
import pl.edu.pk.cc.common.dto.CCWorkerDTO;
import pl.edu.pk.cc.common.util.CCPermissions;
import pl.edu.pk.cc.server.hibernate.CCHibernateUtil;


public class DatabaseInit {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		CCWorkerDTO worker = new CCWorkerDTO("admin","admin",1234567890L,new Date(),"adminowo");
		
		CCLoginDataDTO login = new CCLoginDataDTO("admin","admin","ad@mi.n",CCPermissions.ADMIN);
		CCEmploymentDTO emp = new CCEmploymentDTO(new Date(),36L,2500.00F);
		worker.setLogin(login);
		login.setWorker(worker);
		worker.setEmp(emp);
		emp.setWorker(worker);
		
		CCWorkerDTO worker1 = new CCWorkerDTO("user","user",1234567890L,new Date(),"userowo");
		
		CCLoginDataDTO login1 = new CCLoginDataDTO("user","user","ur@e.r",CCPermissions.USER);
		CCEmploymentDTO emp1 = new CCEmploymentDTO(new Date(),36L,1500.00F);
		worker1.setLogin(login1);
		worker1.setEmp(emp1);
		login1.setWorker(worker1);
		
		emp1.setWorker(worker1);
		
		CCWorkerDTO worker2 = new CCWorkerDTO("chef","chef",1234567890L,new Date(),"chefowo");
		
		CCLoginDataDTO login2 = new CCLoginDataDTO("chef","chef","ch@e.f",CCPermissions.CHIEF);
		CCEmploymentDTO emp2 = new CCEmploymentDTO(new Date(),36L,1500.00F);
		worker2.setLogin(login2);
		worker2.setEmp(emp2);
		login2.setWorker(worker2);
		emp2.setWorker(worker2);
		
		
		
		
		CCClientDTO client1 = new CCClientDTO("klient1", "klient1", 1234455L, new Date(), "klient1");
		CCClientDTO client2 = new CCClientDTO("klient2", "klient2", 1234455L, new Date(), "klient2");
		CCClientDTO client3 = new CCClientDTO("klient3", "klient3", 1234455L, new Date(), "klient3");
		
		CCCallHistoryDTO call1 = new CCCallHistoryDTO(10L, new Date());
		CCCallHistoryDTO call2 = new CCCallHistoryDTO(20L, new Date());
		CCCallHistoryDTO call3 = new CCCallHistoryDTO(30L, new Date());
		
		CCProjectsDTO project1 = new CCProjectsDTO("Przedluzanie umow telekomunikacyjnych", "agreement", null, "Orange",true);
		CCProjectsDTO project2 = new CCProjectsDTO("Zawieranie umow doradczych", "agreement", null, "XYZ",false);
		CCProjectsDTO project3 = new CCProjectsDTO("Sprzedaz telemarketingowa", "sales", "Orbitrek", null,true);
		
		Session s = CCHibernateUtil.getSessionFactory().getCurrentSession();
		Transaction t = s.beginTransaction();
		
		s.save(worker);
		s.save(worker1);
		s.save(worker2);
		
		s.save(client1);
		s.save(client2);
		s.save(client3);
		
		s.save(project1);
		s.save(project2);
		s.save(project3);
		
		call1.setWorker(worker1);
		call1.setClients(client1);
		call1.setProject(project1);
		project1.getCalls().add(call1);
		worker1.getCalls().add(call1);
		client1.getCalls().add(call1);
		call2.setWorker(worker1);
		call2.setClients(client2);
		call2.setProject(project2);
		worker1.getCalls().add(call2);
		client2.getCalls().add(call2);
		project2.getCalls().add(call2);
		call3.setWorker(worker1);
		call3.setClients(client3);
		call3.setProject(project3);
		worker1.getCalls().add(call3);
		client3.getCalls().add(call3);
		project3.getCalls().add(call3);
		
		s.save(call1);
		s.save(call2);
		s.save(call3);
		
		CCAgreementDTO agg1 = new CCAgreementDTO(new Date(), 1);
		CCAgreementDTO agg2 = new CCAgreementDTO(new Date(), 2);
		CCAgreementDTO agg3 = new CCAgreementDTO(new Date(), 3);
		
		agg1.setClients(client1);
		client1.getAgree().add(agg1);
		agg2.setClients(client2);
		client2.getAgree().add(agg2);
		agg3.setClients(client3);
		client3.getAgree().add(agg3);
		
		s.save(agg1);
		s.save(agg2);
		s.save(agg3);
		
		
		CCSaleDTO sale1 = new CCSaleDTO(new Date(), 123.4F, "sale1");
		CCSaleDTO sale2 = new CCSaleDTO(new Date(), 123.4F, "sale2");
		CCSaleDTO sale3 = new CCSaleDTO(new Date(), 1222.4F, "sale3");
		
		sale1.setClients(client1);
		client1.getSales().add(sale1);
		sale2.setClients(client2);
		client2.getSales().add(sale2);
		sale3.setClients(client3);
		client3.getSales().add(sale3);
		
		s.save(sale1);
		s.save(sale2);
		s.save(sale3);
		
		t.commit();
		System.exit(0);
	}

}
